package com.benben.springSecurity.weiwei;

import java.util.Stack;

public class UnixPathTransfer {
    public String simplifyPath(String path){
        String[] strArr = path.split("/");
        Stack<String> stack = new Stack<>();
        for(int i=0;i<stack.size();i++){
            if(!stack.isEmpty() && strArr[i].equals("..")){
                stack.pop();
            }else if(!strArr[i].equals("") && !strArr[i].equals(".") && !strArr[i].equals("..")){
                stack.push(strArr[i]);
            }

        }
        if(stack.isEmpty()){
            return "/";
        }
        StringBuilder result = new StringBuilder();
        for (int i=0;i<stack.size();i++){
            result.append("/" + stack.get(i));
        }
        return result.toString();
    }
}
